<%@ page language="java" pageEncoding="UTF-8"%>

<script type="text/javascript">
var detailValidator;

function doDelete() {
	if (!confirm('是否删除？\n请确认是否继续操作 ！')) {
		return;
	}
	
	block("#detailForm");
	var id = $("#taskId").val();
	$.ajax({
		type: "POST",
		url: "delete.json",
		data: {"id": id},
		dataType: "json",
		success: function(data){
			unblock("#detailForm");
			if(!data.succeed){
				$.alert("删除失败，原因为：\n" + data.message);
				return;
			}
			$.info("删除成功！");
			goBack1();
		},
		error: function(message){
			unblock("#detailForm");
			$.alert("删除失败：" + message);
		}
	});
}

function doSave() {
	if (!detailValidator.form()) {
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "POST",
		url: "save.json",
		data: getTaskData(),
		dataType: "json",
		success: saveSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert("出错了，错误信息为：\n"+message);
		}
	});
}

function loadItem(){
	var id = request("id");
	if(id == undefined || id == ""){
		return;
	}
	
	block("#detailForm");
	$.ajax({
		type: "GET",
		cache: false,
		url: "detail.json?id=" + id,
		dataType: "json",
		success: loadSucceedCallback,
		error:function(message){
			unblock("#detailForm");
			$.alert(message);
		}  
	});	
}

function loadSucceedCallback(data){
	unblock("#detailForm");
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}
	fillItem(data.data);
}

function fillItem(item){
	$("#id").val(item.id);
	$("#name").val(item.name);
	$("#content").val(item.content);
	$("input[name='enable'][value=" + item.enable + "]").attr("checked",true);  
}

$(document).ready(function() {
	//$('#taskPlanStartDate').datepicker();
	$('#taskPlanEndDate').datepicker();
	$("textarea").tah({
		moreSpace:10
	});
	$().maxlength();
	
	loadItem();
	
	detailValidator = $("#detailForm").validate({
		rules: {
			name:{required:true, maxlength:50 }
		},
		messages:{
			name:{required:"请输入模板名称"}
		}
	});

});
</script>

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="id" name="id" />
<fieldset>
	<div class="control-group">
		<label for="name"  class="control-label">名称：</label>
		<div class="controls">
			<input type="text" id="name" name="name" maxlength="50" /> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="content"  class="control-label">任务描述：</label>
		<div class="controls">
			<textarea id="content" name="content" maxlength="1000"></textarea>
		</div> 
	</div>
	<div class="control-group">
		<label for="enable"  class="control-label">状态：</label>
		<div class="controls">
			<label class="radio inline">
            	<input type="radio" value="1" name="enable" id="enable1" checked="checked" >
              	启用
            </label>
            <label class="radio inline">
            	<input type="radio" value="0" name="enable" id="enable0">
            	禁用
            </label>
		</div> 
	</div>
	<div class="form-actions">
		<a id="saveBtn" href="javascript:void(0);" class="btn btn-primary" onclick="doSave()"><i class="icon-ok"></i>保存</a>
		<a id="deleteBtn" href="javascript:void(0);" class="btn btn-danger" onclick="doDelete()"><i class="icon-remove"></i>删除</a>
	</div>
</fieldset>
</form>